package mk.jug.academy.preconditions;

import mk.jug.academy.exception.BusinessException;
import mk.jug.academy.model.Lecturer;
import mk.jug.academy.model.status.LecturerStatus;

import org.springframework.util.Assert;


/**
 * Class separating the concerns of checking preconditions for
 * regarding {@link Lecturer} processes.
 * 
 * It is usually a Precondition <-> Service pair.
 *
 * @author Ice.Penov
 */
public final class LecturerPreconditions {

	/** No instantiation. Static usage only */
	private LecturerPreconditions() {;}
	
	public static void registerLecturer(Lecturer lecturer) {
		Assert.notNull(lecturer.getFirstName(), PreconditionExceptions.MISSING_FIRST_NAME);
		Assert.notNull(lecturer.getLastName(), PreconditionExceptions.MISSING_LAST_NAME);
		Assert.notNull(lecturer.getEmail(), PreconditionExceptions.MISSING_EMAIL);
	}
	
	public static void acceptRegistration(Lecturer lecturer) {
		Assert.notNull(lecturer.getId(), PreconditionExceptions.ID_IS_NULL);
		if (!lecturer.getStatus().equals(LecturerStatus.SIGNED_UP)) {
			throw new BusinessException(ErrorCodes.ERROR_LECTURER_SIGNED_UP_STATE);
		}
	}
	
	public static void rejectRegistration(Lecturer lecturer) {
		Assert.notNull(lecturer.getId(), PreconditionExceptions.ID_IS_NULL);
		if (!lecturer.getStatus().equals(LecturerStatus.SIGNED_UP)) {
			throw new BusinessException(ErrorCodes.ERROR_LECTURER_SIGNED_UP_STATE);
		}
	}
	
	public static void retireLecturer(Lecturer lecturer) {
		Assert.notNull(lecturer.getId(), PreconditionExceptions.ID_IS_NULL);
		if (!lecturer.getStatus().equals(LecturerStatus.ACTIVE)) {
			throw new BusinessException(ErrorCodes.ERROR_LECTURER_ACTIVE_STATE);
		}
	}
	
}
